package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: zm
 * @Date: 2021/8/8 20:22
 */
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;


  // http://api.gmall.com/admin/product/baseTrademark/{page}/{limit}
    @ApiOperation(value = "品牌分页列表")
    @GetMapping("{page}/{limit}")
    public Result getBaseTradeMarekList(@PathVariable() Long page,@PathVariable Long limit){

        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage<BaseTrademark>  iPage= baseTrademarkService.getBaseTradeMarekList(baseTrademarkPage);
        return Result.ok(iPage);
    }

    // http://api.gmall.com/admin/product/baseTrademark/save
    @ApiOperation("保存品牌")
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark trademark){
        baseTrademarkService.save(trademark);
        return Result.ok();
    }

    // http://api.gmall.com/admin/product/baseTrademark/update
    @ApiOperation("修改品牌")
    @PutMapping("update")
    public Result updateTrade(@RequestBody BaseTrademark trademark){
        baseTrademarkService.updateById(trademark);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/baseTrademark/remove/{id}
    @ApiOperation("删除品牌")
    @DeleteMapping("remove/{id}")
    public Result removeById(@PathVariable() Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/baseTrademark/get/{id}
    @ApiOperation("根据id获取品牌属性")
    @GetMapping("get/{id}")
    public Result getById(@PathVariable() Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }


    // http://api.gmall.com/admin/product/baseTrademark/getTrademarkList
    @ApiOperation("获取品牌属性列表")
    @GetMapping("getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }

}
